{extend name='common/container'}
{block name="content"}
<div style="margin:0 15px 15px 15px;">
    <el-card shadow="never" style="min-height:650px;">
        <div class="btn-group" style="margin-top:10px;margin-bottom:10px;">
            <div>
                <el-button v-for="item in button_group" :key="item.access" v-if="checkPermission(item.access,'{:implode(',',session('admin.access'))}','{:session('admin.role_id')}',[1])" :disabled="$data[item.disabled]" :type="item.color" size="mini" :icon="item.icon" @click="fn(item.clickname)">
                    <span v-if="item.batch" v-text="$data['batchUpdateStatus']?'批量保存':'批量编辑'"></span>
                    <span v-else v-text="item.name"></span>
                </el-button>
            </div>
        </div>
        <el-table :row-class-name="rowClass" @selection-change="selection"  @row-click="handleRowClick"  row-key="id"  :header-cell-style="{ background: '#eef1f6', color: '#606266' }" @sort-change='sortChange' v-loading="loading"  ref="multipleTable" border class="eltable" :data="list" :summary-method="getSummaries" show-summary style="width: 100%">
            <el-table-column align="center" type="selection" width="42"></el-table-column>
            <el-table-column align="center" type = '' property="id"  label="编号"  width="70"></el-table-column>
            <el-table-column align="center"  property="position"  label="所属页面"></el-table-column>
            <el-table-column align="center"  property="level"  label="顺序(越大越靠前)"></el-table-column>
            <el-table-column align="center"  property="pic"  label="banner(简体)">
                <template slot-scope="scope">
                    <div class="demo-image__preview">
                        <el-image v-if="scope.row.pic" class="table_list_pic" :src="scope.row.pic"  :preview-src-list="[scope.row.pic]"></el-image>
                    </div>
                </template>
            </el-table-column>
            <el-table-column align="center"  property="e_pic"  label="banner(英)">
                <template slot-scope="scope">
                    <div class="demo-image__preview">
                        <el-image v-if="scope.row.e_pic" class="table_list_pic" :src="scope.row.e_pic"  :preview-src-list="[scope.row.e_pic]"></el-image>
                    </div>
                </template>
            </el-table-column>
            <el-table-column align="center"  property="t_pic"  label="banner(繁)">
                <template slot-scope="scope">
                    <div class="demo-image__preview">
                        <el-image v-if="scope.row.t_pic" class="table_list_pic" :src="scope.row.t_pic"  :preview-src-list="[scope.row.t_pic]"></el-image>
                    </div>
                </template>
            </el-table-column>


            <el-table-column align="center"  property="add_time"  label="添加时间"  width=""></el-table-column>
            <el-table-column :fixed="ismobile()?false:'right'" label="操作" align="center" width="180">
                <template slot-scope="scope">
                    <div v-if="scope.row.id">
                        <el-button v-if="checkPermission('/admin/Member/update.html','{:implode(",",session("admin.access"))}','{:session("admin.role_id")}',[1])" size="mini" icon="el-icon-edit" type="primary" @click="update(scope.row)" >修改</el-button>
                        <el-button v-if="checkPermission('/admin/Member/delete.html','{:implode(",",session("admin.access"))}','{:session("admin.role_id")}',[1])" size="mini" icon="el-icon-delete" type="danger" @click="del(scope.row)" >删除</el-button>
                    </div>
                </template>
            </el-table-column>
        </el-table>
        <Page :total="page_data.total" :page.sync="page_data.page" :limit.sync="page_data.limit" @pagination="index" />
    </el-card>

    <!--添加-->
    <Add :show.sync="dialog.addDialogStatus" size="small" @refesh_list="index"></Add>
    <!--修改-->
    <Update :info="updateInfo" :show.sync="dialog.updateDialogStatus" size="small" @refesh_list="index"></Update>
    <!--查看详情-->
    <Detail :info="detailInfo" :show.sync="dialog.detailDialogStatus" size="small" @refesh_list="index"></Detail>

</div>

{/block}
{block name="script"}
<script src="__PUBLIC__/assets/js/app.js"></script>
<script src="__PUBLIC__/assets/libs/xlsx/xlsx.core.min.js"></script>
<script src="__PUBLIC__/components/admin/banner/add.js?v=<?php echo rand(1000,9999)?>"></script>
<script src="__PUBLIC__/components/admin/banner/update.js?v=<?php echo rand(1000,9999)?>"></script>
<script>
    new Vue({
        el: '#app',
        components:{
        },
        data: function() {
            return {
                dialog: {
                    addDialogStatus : false,
                    updateDialogStatus : false,
                    detailDialogStatus : false,
                    resetPwdDialogStatus : false,
                    importDataDialogStatus : false,
                },
                searchData:{},
                button_group:[
                    {name:'添加',color:'success',access:'/admin/Banner/add.html',icon:'el-icon-plus',disabled:'',clickname:'add'},
                    // {name:'修改',color:'primary',access:'/admin/Charitable/edit.html',icon:'el-icon-edit',disabled:'single',clickname:'update'},
                    {name:'删除',color:'danger',access:'/admin/Banner/delete.html',icon:'el-icon-delete',disabled:'multiple',clickname:'del'},
                ],
                loading: false,
                position_list:{},
                page_data: {
                    limit: 20,
                    page: 1,
                    total:20,
                },
                updateInfo:{},

            }
        },
        methods:{
            index(){
                let param = {limit:this.page_data.limit,page:this.page_data.page,order:this.order,sort:this.sort}
                Object.assign(param, this.searchData,this.urlobj)
                this.loading = true
                axios.post(base_url + '/banner/position').then(res => {
                    if(res.data.status == 200){
                        this.position_list = res.data.data
                    }
                })
                axios.post(base_url + '/Banner/index',param).then(res => {
                    if(res.data.status == 200){
                        this.list = res.data.data.data
                        this.page_data.total = res.data.data.total
                        this.sum_amount = res.data.sum_amount
                        this.loading = false
                    }else{
                        this.$message.error(res.data.msg);
                    }
                })

            },
            add(){
                this.dialog.addDialogStatus = true
            },
            update(row){
                let id = row.id ? row.id : this.ids.join(',')
                axios.post(base_url + '/Banner/getEdit',{id:id}).then(res => {
                    if(res.data.status == 200){
                        this.dialog.updateDialogStatus = true
                        this.updateInfo = res.data.data
                    }else{
                        this.$message.error(res.data.msg)
                    }
                })
            },
            del(row){
                this.$confirm('确定操作吗?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let ids = row.id ? row.id : this.ids.join(',')
                    axios.post(base_url + '/Banner/delete',{id:ids}).then(res => {
                        if(res.data.status == 200){
                            this.$message({message: res.data.msg, type: 'success'})
                            this.index()
                        }else{
                            this.$message.error(res.data.msg)
                        }
                    })
                }).catch(() => {})
            },
            fn(method){
                this[method](this.ids)
            },
        },

        mounted(){
            this.index()
        },
    })
</script>
{/block}
